package com.ujs.listnode.code;

/**
 * @author zhangshihao
 * @create 2023-10-09 20:23
 */
public class NodeInit {
    public static ListNode getNode() {
        ListNode head = new ListNode(1);
        ListNode node1 = new ListNode(2);
        ListNode node2 = new ListNode(3);
        ListNode node3 = new ListNode(4);
        ListNode node4 = new ListNode(5);
        ListNode node5 = new ListNode(6);
        head.next = node1;
        node1.setNext(node2);
        node2.setNext(node3);
        node3.setNext(node4);
        node4.setNext(node5);
        node5.setNext(null);
        return head;
    }

    public static ListNode getListByNums(int[] nums) {
        ListNode head = new ListNode(nums[0]);
        ListNode cur = head;
        for (int i = 1; i < nums.length; i++) {
            cur.next = new ListNode(nums[i]);
            cur = cur.next;
        }
        return head;
    }

    public static void main(String[] args) {
        ListNode head = getListByNums(new int[]{1, 2, 3});
        while (head != null) {
            System.out.print(head.getVal() + " ");
            head = head.getNext();
        }
    }
}
